import Vue from 'vue'
import App from './App3.vue'
function toArray(list, start) {
  start = start || 0
  let i = list.length - start
  const ret = new Array(i)
  while (i--) {
    ret[i] = list[i + start]
  }
  return ret
}
Vue.use = function (plugin) {
  // this._installedPlugins 存储的是已经装过的插件
  // debugge  r
  const installedPlugins = (this._installedPlugins || (this._installedPlugins = []))
  if (installedPlugins.indexOf(plugin) > -1) {
    // r若是已经安装的插件  则 不逊要再去执行下边的安装逻辑了  优化
    return this
  }

  // additional parameters
  const args = toArray(arguments, 1) //从实参集合中 从索引为1的地方把后边的参数放到一个数组力
  // [1, 2, 3, 4, 5]
  args.unshift(this)// [Vue,1, 2, 3, 4, 5]
  if (typeof plugin.install === 'function') {
    plugin.install.apply(plugin, args)
  } else if (typeof plugin === 'function') {
    plugin.apply(null, args)
  }
  installedPlugins.push(plugin)
  return this
}
Vue.use({
  install(_Vue) {
    console.log(arguments)//Vue,1, 2, 3, 4, 5
  }
}, 1, 2, 3, 4, 5)
function plug1() {
  console.log(arguments)//Vue,1, 2, 3, 4, 5
}
plug1.install = function (_Vue) {
  console.log('plug1的instatll')
  _Vue.component()
}
Vue.use(plug1, 1, 2, 3, 4, 5)
Vue.use(plug1, 1, 2, 3, 4, 5)

Vue.component('my-loading2', {
  render(h) {
    return h('h1', { class: 'box', attrs: { qqq: '111' } }, ['loading', h('span', '666')])
  },
  // template
})
new Vue({
  render: h => h(App)
}).$mount('#app')